<template>
	<om-formsub-outer :index="index" :checkedit="checkedit">
		<om-autoform ref="autoform" :edit="edit" :checkedit="checkedit" :initConfigData="autoformdata" :initValue="initValue"></om-autoform>
	</om-formsub-outer>
</template>

<script>
	import {
		buildSubFormData,
		subOnLoad,
		changeEditor,
		configSelectData
	} from '../../../static/js/formUtil.js';
	import {
		ignoreHtml,
		errorModal,
		ptFloat,
		minusF,
		getDateStr
	} from '@/static/js/common.js';
	import urlUtil from '@/static/js/urlUtil.js';
	export default {
		provide() {
			return {
				formPage: this
			};
		},
		data() {
			return buildSubFormData({
				supplierCacheKey:'rps-gf-qualifiedSupplier-supplier-cache',
				adjustedConclusionCacheKey:'rps-gf-qualifiedSupplier-adjustedConclusion-cache'
			})
		},
		methods:{
			getQualifiedSupplierShowNew(id){
				let _that = this
				_that.om.request(
					"qualifiedSupplierShow/getQualifiedSupplierShowNew",
					{
						supplierId: id
					}
				).then(res=>{
					if(res.value){
						_that.$refs.autoform.formdata.remark = res.value.remark
						_that.$refs.autoform.formdata.originalEffectiveDay = res.value.effectiveDate
					}
				})
			},
			
			initload(){
				let _that = this
			},
			
		},
		onLoad(e) {
			let _that = this
			subOnLoad(_that, e, function() {
				if (e.configDataCacheKey) {
					uni.getStorage({
						key: e.configDataCacheKey,
						success: function(res) {
							//if (res.data && res.data instanceof Array) {
							if(res.data && Object.prototype.toString.call(res.data)==='[object Array]'){
								_that.autoformdata = res.data
							}
							Object.assign(_that.initValue, _that.formdata)
							_that.autoformdata[0].order = _that.order
							changeEditor(_that.autoformdata[0].editors, 'fileList', 'fileUploadKey', '60');
							if (_that.formdata.fileList) {
								var tempFileList = [];
								var fileUrlList = _that.formdata.fileList.map(t => {
									tempFileList.push(t.fileSaveName);
									return t.fileSaveName;
								});
								changeEditor(_that.autoformdata[0].editors, 'fileList', 'fileUrlList', fileUrlList);
								changeEditor(_that.autoformdata[0].editors, 'fileList', 'tempFileList', tempFileList);
							}
							changeEditor("title2","supplierId",{
								link:'../../public/pageSearch/pageSearch',
								"linkParam":{
									other:JSON.stringify({}),
									namefield:'supplierCode',
									notefield:'supplierShortName',
									placeholder:'',
									url:'supplierEvaluationConfirm/likeSerchAllSupplier',
									initload:true,
									cachename:_that.supplierCacheKey,
									searchfield:'q'  
								}
							 },null,_that.autoformdata)
							changeEditor("title2","adjustedConclusionId",{
								link:'../../public/pageSearch/pageSearch',
								"linkParam":{
									other:JSON.stringify({
										code:'39246'
									}),
									namefield:'dicname',
									notefield:'remark',
									placeholder:'',
									url:'tsysdict/getListByCode',
									initload:true,
									cachename:_that.adjustedConclusionCacheKey,
									searchfield:'q'
								}
							 },null,_that.autoformdata)
							_that.$nextTick(function(){
								
							})
						}
					})
				}
			})
		},
		onShow() {
			let _that = this
			if (_that.$refs.autoform) {
				uni.getStorage({
					key:_that.supplierCacheKey,
					success:(res)=>{
						if(res.data){
							let d = res.data
							let formdata = _that.$refs.autoform.formdata
							let hasSupplierId = []
							hasSupplierId = _that.datas.filter((item)=>{
								return item.supplierId == d.supplierId
							});
							if(hasSupplierId.length){
								errorModal(_that,'提示信息','合格供方重复评价',()=>{})
							}else{
								formdata.supplierId = d.supplierId
								formdata.supplierCode = d.supplierCode
								formdata.supplierShortName = d.supplierShortName
								formdata.supplierName = d.supplierName
								formdata.maintainUserName = d.maintainUserName
								formdata.remark = d.remark
								formdata.evaluationConclusion = d.adjustedConclusion
								_that.getQualifiedSupplierShowNew(d.supplierId)
							}
						}
						uni.removeStorage({
							key:_that.supplierCacheKey
						})
					}
				})
				uni.getStorage({
					key:_that.adjustedConclusionCacheKey,
					success:(res)=>{
						if(res.data){
							let d = res.data
							let formdata = _that.$refs.autoform.formdata
							formdata.adjustedConclusionId = d.id
							formdata.adjustedConclusion = d.dicname
							uni.removeStorage({
								key:_that.adjustedConclusionCacheKey
							})
						}
					}
				})
			}
		}
	}
</script>

<style>
</style>
